home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / alaw sdec scom / componentdispatch.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  9.4 KB  |  207 lines

  1. /*
  2.     File:        ComponentDispatch.h
  3.  
  4.     Contains:    Header for common routines for dispatching for a sound component
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/13/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. //    Sound Component Function Prototypes
  25.  
  26. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // component stuff
  28. #pragma once
  29. #include <SoundComponents.h>
  30. #ifdef COMPRESSION
  31.     #define kOutputSampleFormat                'ALAW'            // output sample format
  32. #endif
  33. #ifdef DECOMPRESSION
  34.     #define kOutputSampleFormat                'twos'            // output sample format
  35. #endif
  36.  
  37. #define kMaxOutputSamples                1024            // max no. samples in output buffer
  38. #define SoundComponentEntryPoint        ALAWCompressor
  39. #define kSoundComponentVersion            0x00010000        // version for this sound component
  40. #define kRequiredSndMgrMajorRev            3                // Sound Manager version required to run this component
  41.  
  42. #define kOutputSampleSize                16                // output sample size
  43.  
  44. typedef struct {
  45.  
  46. // these are general purpose variables that every sound component will need
  47.     ComponentInstance        sourceComponent;            // component to call when we need more data
  48.     SoundComponentDataPtr    sourceDataPtr;                // pointer to source data structure
  49.     SoundComponentData        thisComponent;                // description of this component's output
  50.     Handle                    globalsHandle;                // handle to component globals
  51.     short                    outputFrames;                // max no. frames in output buffer
  52.     short                    outputSamples;                // max no. samples in output buffer
  53.     CompressionInfo            compInfo;                    // info about compressor
  54.     CompressionInfo            destCompInfo;                // info about destination
  55.     Boolean                    reverse;                    // true if data should be played back in reverse
  56.     Boolean                    pad1;
  57.     Byte                    buffer[kMaxOutputSamples * 2];    // room for 8-bit, stereo samples
  58. } SoundComponentGlobals, *SoundComponentGlobalsPtr;
  59.  
  60. #ifdef COMPRESSION
  61. void    InitializeCompressor    (SoundComponentGlobalsPtr globals);
  62. void    CompressALaw            (short *inbuf, Byte *outbuf, unsigned long framesToConvert, unsigned long numChannels);
  63. #endif
  64. #ifdef DECOMPRESSION
  65. void    InitializeDecompressor    (SoundComponentGlobalsPtr globals);
  66. void    DecompressALaw            (Byte *inbuf, short *outbuf, unsigned long framesToConvert, unsigned long numChannels);
  67. #endif
  68.  
  69. ComponentResult            PrimeSource                (SoundComponentGlobalsPtr globals);
  70.  
  71. void                    GetCompressorInfo        (CompressionInfoPtr cp);
  72.  
  73. pascal ComponentResult __SoundComponentOpen(void *unused1, ComponentInstance self);
  74. pascal ComponentResult __SoundComponentClose(SoundComponentGlobalsPtr globals, ComponentInstance self);
  75. pascal ComponentResult __SoundComponentRegister(SoundComponentGlobalsPtr globals);
  76. pascal ComponentResult __SoundComponentCanDo(void *unused1, short selector);
  77.  
  78. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. // basic stuff
  80.  
  81. pascal ComponentResult __SoundComponentSetSource(SoundComponentGlobalsPtr globals, SoundSource sourceID, ComponentInstance source);
  82. pascal ComponentResult __SoundComponentGetSourceData(SoundComponentGlobalsPtr globals, SoundComponentDataPtr *sourceData);
  83. pascal ComponentResult __SoundComponentSetOutput(SoundComponentGlobalsPtr globals, SoundComponentDataPtr requested, SoundComponentDataPtr *actual);
  84.  
  85. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. // info methods
  87.  
  88. pascal ComponentResult __SoundComponentGetInfo(SoundComponentGlobalsPtr globals, SoundSource sourceID, OSType selector, void *infoPtr);
  89.  
  90. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. // control methods
  92.  
  93. pascal ComponentResult __SoundComponentStopSource(SoundComponentGlobalsPtr globals, short count, SoundSource *sources);
  94. pascal ComponentResult __SoundComponentPlaySourceBuffer(SoundComponentGlobalsPtr globals, SoundSource sourceID, SoundParamBlockPtr pb, long actions);
  95.  
  96. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. // types
  98. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99.  
  100. #if GENERATINGPOWERPC
  101.  
  102. // These structs are use in PowerMac builds to cast the
  103. // ComponentParameters passed into our component's entry point.
  104.  
  105. enum {
  106.     uppSoundComponentEntryPointProcInfo = kPascalStackBased
  107.         | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  108.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentParameters *)))
  109.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void *)))
  110. };
  111.  
  112. // These are used to create the routine descriptor to call each function.
  113.  
  114. enum {
  115.         upp__SoundComponentOpenProcInfo = kPascalStackBased
  116.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  117.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void *)))
  118.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance)))
  119. };
  120.  
  121. enum {
  122.         upp__SoundComponentCloseProcInfo = kPascalStackBased
  123.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  124.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  125.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(ComponentInstance)))
  126. };
  127.  
  128. enum {
  129.         upp__SoundComponentRegisterProcInfo = kPascalStackBased
  130.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  131.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  132. };
  133.  
  134. enum {
  135.         upp__SoundComponentSetSourceProcInfo = kPascalStackBased
  136.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  137.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  138.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource)))
  139.                 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ComponentInstance)))
  140. };
  141.  
  142. enum {
  143.         upp__SoundComponentGetSourceDataProcInfo = kPascalStackBased
  144.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  145.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  146.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundComponentDataPtr)))
  147. };
  148.  
  149. enum {
  150.         upp__SoundComponentSetOutputProcInfo = kPascalStackBased
  151.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  152.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  153.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundComponentDataPtr)))
  154.                 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundComponentDataPtr)))
  155. };
  156.  
  157. enum {
  158.         upp__SoundComponentGetInfoProcInfo = kPascalStackBased
  159.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  160.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  161.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource)))
  162.                 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(OSType)))
  163.                 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void *)))
  164. };
  165.  
  166. enum {
  167.         upp__SoundComponentStopSourceProcInfo = kPascalStackBased
  168.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  169.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  170.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  171.                 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundSource)))
  172. };
  173.  
  174. enum {
  175.         upp__SoundComponentPlaySourceBufferProcInfo = kPascalStackBased
  176.                 | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  177.                 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SoundComponentGlobalsPtr)))
  178.                 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SoundSource)))
  179.                 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(SoundParamBlockPtr)))
  180.                 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  181. };
  182.  
  183. #define CallComponentFunctionWithStorageUniv(storage, params, funcName) \
  184.         CallComponentFunctionWithStorage(storage, params, &funcName##RD)
  185. #define CallComponentFunctionUniv(params, funcName) \
  186.         CallComponentFunction(params, &funcName##RD)
  187. #define INSTANTIATE_ROUTINE_DESCRIPTOR(funcName) RoutineDescriptor funcName##RD = \
  188.         BUILD_ROUTINE_DESCRIPTOR (upp##funcName##ProcInfo, funcName)
  189.  
  190. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentRegister);
  191. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentClose);
  192. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentOpen);
  193. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentSetSource);
  194. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentGetSourceData);
  195. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentSetOutput);
  196. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentGetInfo);
  197. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentStopSource);
  198. INSTANTIATE_ROUTINE_DESCRIPTOR(__SoundComponentPlaySourceBuffer);
  199.  
  200. #else //GENERATING68K
  201.  
  202. #define CallComponentFunctionWithStorageUniv(storage, params, funcName) \
  203.         CallComponentFunctionWithStorage(storage, params, (ComponentFunctionUPP)funcName)
  204. #define CallComponentFunctionUniv(params, funcName) \
  205.         CallComponentFunction(params, (ComponentFunctionUPP)funcName)
  206. #endif
  207.